/**
 * Created by liqiao on 2017/11/24.
 */
import {Injectable} from '@angular/core';
import {Http}from '@angular/http';
import 'rxjs/add/operator/map';
import { environment } from '../../environments/environment'

@Injectable()
export class UserService {
  users: string[];
  url: string;

  constructor(public http: Http) {
      this.users = ["mr.li", "17", "liqiao"];
      this.url = environment.host + ":" + environment.port;
  }

  getUsers() {
    // return this.http.get("http://jsonplaceholder.typicode.com/users")
    return this.http.get(this.url + "/user")
      .map(res => res.json());
  }

  findByUserNo(userNo) {
    return this.http.get(this.url + "/user/findByUserNo/" + userNo)
      .map(res => res.json());
  }

  findByUserName(userName) {
    return this.http.get(this.url + "/user/findByUserName/" + userName)
      .map(res => res.json());
  }

  findByUserAddr(userAddr) {
    return this.http.get(this.url + "/user/findByUserAddr/" + userAddr)
      .map(res => res.json());
  }

  findByUserTel(userTel) {
    return this.http.get(this.url + "/user/findByUserTel/" + userTel)
      .map(res => res.json());
  }

  addUser(user) {
    return this.http.post(this.url + "/user/add", user)
      .map(res => res.json());
  }

  deleteUser(id) {
    return this.http.get(this.url + "/user/delete/" + id)
      .map(res => res.json());
  }

    openDev(id) {

    }

    closeDev(id) {

    }
}
